// @created: caoshi
// @date: 2021-06-21 20:03
package middleware

import (
	"academic/global"
	"academic/model/request"
	"fmt"
	"github.com/dgrijalva/jwt-go"
)

type JWT struct {
	StringKey []byte // 唯一签名
}

func NewJWT() *JWT {
	return &JWT{
		StringKey: []byte(global.GvaConfig.JWT.StringKey),
	}
}

// 创建token
func (j *JWT) CreateToken(claims request.CustomClaims) (string, error) {
	token := jwt.NewWithClaims(jwt.SigningMethodES256, claims)
	return token.SignedString(j.StringKey)
}

// 解析token
func (j *JWT) parseToken() {
	fmt.Println("hehh")
}
